<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<html>
	<body style="height: 100%; width: 100%; overflow: hidden; border: none;">
		<script type="text/javascript">
			$("document").ready(function(){
				debugger;
				$('#roleMenuTree').tree({
					checkbox: true,
					url: '${pageContext.request.contextPath}/sys/role.do?queryMenuTree&roleid='+$('#adminRoleTable').datagrid('getSelections')[0].id,
					cascadeCheck:false,
					onClick:function(node){
						debugger;
						$(this).tree('toggle', node.target);
						//alert('you dbclick '+node.attributes);undefined
						//alert('you dbclick '+node.attributes.url);
					}
				});
			});
				
			function addOrUpdateRoleMenuTree(){
				debugger;
				var r = $('#roleMenuTreeForm').form('validate');
				if(!r) {
					return false;
				}
				
				var rows  = $('#adminRoleTable').datagrid('getSelections');
				var roleid = rows[0].id;//角色 id
				
				var nodes = $('#roleMenuTree').tree('getChecked');
				var s = '';
				for(var i=0; i<nodes.length; i++){
					if (s != '') s += ',';
					s += nodes[i].id;
				}
				
				var roleMenuParam={roleid:roleid,functionid:s};
				//alert(roleMenuParam.roleid);
				//alert(roleMenuParam.functionid);
				$.post("${pageContext.request.contextPath}/sys/role.do?addOrUpdateRoleMenu",roleMenuParam,function(data){
					$('#MyPopWindow').window('close');
					//$('#adminRoleTable').datagrid('reload');  
					$.messager.alert('提示',data.msg,'info');
				});
			}
			$('#roleMenuTreePopPanel').panel();
			
			//重新加载
			function reloadRoleMenuTree(){
				var node = $('#roleMenuTree').tree('getSelected');
				if (node){
					$('#roleMenuTree').tree('reload', node.target);
				} else {
					$('#roleMenuTree').tree('reload');
				}
			}
			//全部折叠
			function collapseAllRoleMenuTree(){
				var node = $('#roleMenuTree').tree('getSelected');
				if (node){
					$('#roleMenuTree').tree('collapseAll', node.target);
				} else {
					$('#roleMenuTree').tree('collapseAll');
				}
			}
			//全部展开
			function expandAllRoleMenuTree(){
				var node = $('#roleMenuTree').tree('getSelected');
				if (node){
					$('#roleMenuTree').tree('expandAll', node.target);
				} else {
					$('#roleMenuTree').tree('expandAll');
				}
			}
			
			
		</script>
		<form id="roleMenuTreeForm" method="post" >
			<div id="roleMenuTreePopPanel"  collapsible="true" >
				<div region="center" border="false" >
					<div style="margin:10px;">
						<a href="#" onclick="reloadRoleMenuTree()">刷新</a>
						<a href="#" onclick="collapseAllRoleMenuTree()">全部折叠</a>
						<a href="#" onclick="expandAllRoleMenuTree()">全部展开</a>
					</div>
					<ul id="roleMenuTree"></ul>
				</div>
				<div region="south" border="false" style="text-align:right;height:30px;line-height:30px;">
					<a href="#" id="btn-back" onclick="closeWindow();" class="easyui-linkbutton" iconCls="icon-back">返回</a>
					<a href="#" id="btn-add" onclick="addOrUpdateRoleMenuTree();" class="easyui-linkbutton" iconCls="icon-save">保存</a>
				</div>
			</div>
		</form>
	</body></html>